<?php

namespace app\common\service;

use app\common\job\ARYPush;
use think\facade\Config;
use think\facade\Queue;

/**
 * 案如云延迟推送服务
 * Class ARYPushService
 * @package app\common\service
 */
class ARYPushQueueService implements \app\common\service\ARYPushInterface
{

    /**
     * 推送问题
     * @param $id
     * @return bool
     */
    public function pushQuestion($id): bool
    {
        $delay = Config::get('ary.question_time', 5 * 60);

        $job_data = ['method' => __FUNCTION__, 'args' => func_get_args()];
        Queue::later($delay, ARYPush::class, $job_data);

        return true;
    }

    /**
     * 推送咨询表单
     * @param $id
     * @return bool
     */
    public function pushConsultingForm($id): bool
    {
        $delay = Config::get('ary.consulting_form_time', 5 * 60);

        $job_data = ['method' => __FUNCTION__, 'args' => func_get_args()];
        Queue::later($delay, ARYPush::class, $job_data);

        return true;
    }

    /**
     * 推送落地页
     * @param $id
     * @param $force
     * @return bool
     */
    public function pushLanding($id, $force = false): bool
    {
        $job_data = ['method' => __FUNCTION__, 'args' => func_get_args()];

        if ($force) {
            Queue::push(ARYPush::class, $job_data);
        } else {
            $delay = Config::get('ary.landing_time', 5 * 60);
            Queue::later($delay, ARYPush::class, $job_data);
        }


        return true;
    }

    /**
     * 推送打官司
     * @param $id
     * @param $force
     * @return bool
     */
    public function pushLawsuit($id, $force = false): bool
    {
        $job_data = ['method' => __FUNCTION__, 'args' => func_get_args()];

        if ($force) {
            Queue::push(ARYPush::class, $job_data);
        } else {
            $delay = Config::get('ary.lawsuit_time', 5 * 60);
            Queue::later($delay, ARYPush::class, $job_data);
        }

        return true;
    }
}
